<template>
	<view>

		<cu-custom :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">登录</block>
		</cu-custom>
		<view class="cu-form-group margin-top page-top">
			<view class="title">账号:</view>
			<input placeholder="用户名或邮箱" v-model="form.username"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">密码: </view>
			<input type="password" placeholder="请输入密码" v-model="form.password"></input>
		</view>
		<view class="padding flex flex-direction">
			<button class="cu-btn bg-olive lg" @click="submit()">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {},
			}
		},
		methods: {
			submit() {
				this.crud.post(this.path, "/api/client/all/user/login", this.form).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: "登录成功",
							icon: 'none'
						})
						// 保存token
						var token  = res.header.TOKEN;
						if(token == null){
							token = res.header.token;
						}
						uni.setStorageSync('XJ-TOKEN',token);
						console.log( "token:" +  token)
						
						// 跳回上页
						uni.switchTab({
							url: "/pages/fpage4/index",
							success: res => {},
							fail: () => {},
							complete: () => {}
						});
					}
				})
			},
		},
		onshow: {

		}
	}
</script>

<style>

</style>
